{{ template "header" . }}
{{ template "navlist" . }}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <div class="layadmin-header">
        <div class="layui-card layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
            <a lay-href="">主页</a><span lay-separator="">/</span>
            <a><cite>根据数据库生成代码-数据表选择</cite></a>
        </div>
    </div>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">
                <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                    <div class="layui-inline">
                        <input class="layui-input" placeholder="请输入数据表名称" name="searchKey" id="searchKey" autocomplete="off">
                    </div>
                    <button class="layui-btn" onclick="searchByKey()" data-type="reload">搜索</button>

                    <button onclick="goNext()" class="layui-btn  pull-right">下一步</button>
                    <a href="/gen/setting"  class="layui-btn layui-btn-primary pull-right">上一步</a>
                </div>
            </div>
            <div class="layui-card-body">
                <table class="layui-hide" id="dblist"></table>
            </div>
        </div>
    </div>
</div>
<!-- /.content-wrapper -->
{{ template "footer" . }}

<script type="text/javascript">
    $(function () {
        $.setupAjaxByOpts({})
        var table=layui.table;

        table.render({
            elem: '#dblist'
            , url: '/gen/tables'
            ,id:"dblistjs"
            ,method: 'post'
            , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                , groups: 5 //只显示 1 个连续页码
                , limit:10 // 默认10条记录
                , first: false //不显示首页
                , last: false //不显示尾页
            }
            , cols: [[
                {type:'numbers', fixed: 'left'},
                {type:'checkbox', fixed: 'left'},
                  {field: 'tableName', width: 250, title: '表名称',fixed: 'left'}
                , {field: 'tableComment',  title: '表描述', sort: true}
            ]]
        });
    })
    function getCheckData(){ //获取选中数据
        var checkStatus = layui.table.checkStatus('dblistjs')
                ,data = checkStatus.data;
        var tableNameList =[];
        if(data.length>0){
            for(i=0;i<data.length;i++){
                tableNameList.push(data[i].tableName)
            }
        }
        return tableNameList;
    }

    function goNext() {
        var data =getCheckData();
        console.log(data)
        if(data.length==0){
            $.showErrorMsg("请选择待处理数据")
            return
        }
        $.scopeAjax({
            url:"/gen/process",
            params:{list:data},
            successCallback:function (data) {
               location.href="/gen/console?"
            }
        })
    }
    
    function searchByKey() {
        //执行重载
        layui.table.reload('dblistjs', {
            page: {
                curr: 1 //重新从第 1 页开始
            }
            ,where: {
                tableName:$("#searchKey").val()
            }
        });
    }
</script>
